﻿<%@ WebHandler Language="C#" Class="AddReview" %>
using System;
using System.Web;
using fanfu.Model;
using fanfu.Common;
using fanfu.Business;

public class AddReview : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        string ParentId = HttpContext.Current.Request.Params["ParentId"].ToString();
        string ParentName = HttpContext.Current.Request.Params["ParentName"].ToString();
        string ParentType = HttpContext.Current.Request.Params["ParentType"].ToString();
        string ReviewerName = HttpContext.Current.Request.Params["ReviewerName"].ToString();
        string ReviewerEmail = HttpContext.Current.Request.Params["ReviewerEmail"].ToString();
        string ReviewerUrl = HttpContext.Current.Request.Params["ReviewerUrl"].ToString();
        string ReviewerIP = HttpContext.Current.Request.Params["ReviewerIP"].ToString();
        string ReviewContent = HttpContext.Current.Request.Params["ReviewContent"].ToString();
        context.Response.Write(InsertReview(ParentId, ParentName, ParentType, ReviewerName,
            ReviewerEmail, ReviewerUrl, ReviewerIP, ReviewContent));
    }
    
    public bool IsReusable {
        get {
            return false;
        }
    }

    public string InsertReview(string ParentId, string ParentName, string ParentType,
                            string ReviewerName, string ReviewerEmail, string ReviewerUrl,
                            string ReviewerIP, string ReviewContent)
    {
        ReviewModel reviewModel = new ReviewModel();
        reviewModel.ParentName = ParentName;
        reviewModel.ParentId = Convert.ToInt32(ParentId);
        reviewModel.ParentType = Convert.ToByte(ParentType);
        reviewModel.BaseId = 0;
        reviewModel.ReviewerName = ReviewerName;
        reviewModel.ReviewerEmail = ReviewerEmail;
        reviewModel.ReviewerUrl = ReviewerUrl;
        reviewModel.ReviewerIP = ReviewerIP;
        reviewModel.ReviewContent = ReviewContent;
        reviewModel.ReviewTime = DateTime.Now;
        reviewModel.Flag = (int)ReviewFlag.noRead;
        int result = SqlHelper.ExecuteCommand(ReviewModel.GetInsertSQL(), reviewModel.ToSqlParameters());
        if (result == 1)
        {
            new ArticleRule().CommentCountPlusOne(ParentId);
            return new ReviewRule().CreateReviewListHtml(ParentId, int.Parse(ParentType)).ToString();
        }
        else
        {
            return result.ToString();
        }
    }
}